package hbase.app

import java.text.SimpleDateFormat

import com.google.gson.JsonParser
import org.apache.commons.lang3.time.FastDateFormat

/**
  * Created on 2019-08-14 15:26.
  */
object Test {
  def splitTime(time:String, srcFormat:String, destFormats:String) :String = {
    val sdf = new SimpleDateFormat(srcFormat)
    val timestr =new SimpleDateFormat("yyyyMMddHHmm")format(sdf.parse(time))
    destFormats.split(",").map(format => {
      format match {
        case "yyyy" => timestr.substring(0, 4)
        case "yy" => timestr.substring(4, 6)
        case "yyyyMM" => timestr.substring(0, 6)
        case "yyyyMMdd" => timestr.substring(0, 8)
        case "yyyyMMddHH" => timestr.substring(0, 10)
        case "yyMM" => timestr.substring(2, 6)
        case "yyMMdd" => timestr.substring(2, 8)
        case "HH" => timestr.substring(8, 10)
        case "HHMM" => timestr.substring(8, 12)
        case "MM" => timestr.substring(10, 12)
        case "M5" => timestr.substring(10, 11) + timestr.substring(11, 12).toInt/5*5
      }
    }).mkString(",")

  }

  def main(args: Array[String]): Unit = {
    splitTime("2019-08-14 17:58:34", "yyyy-MM-dd HH:mm:ss", "yyMMdd,HH,M5,")

  }
}
